package com.jinzhu.common.httpclient;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.spring.PropertyPreFilters;

import java.util.Objects;

/**
 * @author  jz
 * 指定排除属性过滤器并且根据首字母排序
 */
public class ExcludeJsonProperties {


    public static String excludeProperties(Object obj,String... excludes){
        PropertyPreFilters filters = new PropertyPreFilters();
        PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
        if(!Objects.equals(null,excludes)){
            excludefilter.addExcludes(excludes);
        }

        JSONObject.toJSONString(obj);
        String json = JSONObject.toJSONString(obj, excludefilter, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,SerializerFeature.MapSortField);

        return json;
    }
}
